<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
    <title>ShellCheck: SC2250 – Prefer putting braces around variable references even when not strictly required.</title>
    <link rel="stylesheet" href="css/bootstrap.min.css" />
  </head>
  <body style="margin-left: auto; margin-right: auto; max-width: 800px">
    <h1>SC2250 – ShellCheck Wiki</h1>
    <a href="https://github.com/koalaman/shellcheck/wiki/SC2250">See this page on GitHub</a>
    <p style="display: none"><a href="index.html">Sitemap</a></p>
    <hr />
    <h2
id="prefer-putting-braces-around-variable-references-even-when-not-strictly-required">Prefer
putting braces around variable references even when not strictly
required.</h2>
<p>This is an <a href="optional.html">optional</a> suggestion. It must be
explicitly enabled with a <a href="directive.html">directive</a>
<code>enable=require-variable-braces</code> in a
<code># shellcheck</code> comment or <code>.shellcheckrc</code></p>
<h2 id="problematic-code">Problematic code:</h2>
<pre class="shell"><code>partial_path=&#39;example&#39;

curl &quot;http://example.com/$partial_path_version/explain.html&quot;</code></pre>
<h2 id="correct-code">Correct code:</h2>
<pre class="shell"><code>partial_path=&#39;example&#39;

curl &quot;http://example.com/${partial_path}_version/explain.html&quot;</code></pre>
<h2 id="rationale">Rationale:</h2>
<p>If a variable gets called, and there is a string that gets appended
to the variable that could get misinterpreted as possibly part of the
name of the variable. Then it will not call the right variable.</p>
<h2 id="related-resources">Related resources:</h2>
<ul>
<li><a
href="https://stackoverflow.com/questions/18320133/how-do-we-separate-variables-from-letters-in-shell-scripting">StackOverflow:
How do we separate variables from letters in shell scripting</a></li>
</ul>
    <hr />
    <p style='font-size: 80%'><a href="../index.html">ShellCheck</a> is a static analysis tool for shell scripts. This page is part of its documentation.</p>
  </body>
</html>


